package ns.gflex.util

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

/**
 * Functions
 * @since Dec 22, 2010
 * @author wangchu
 */
class Encoder {
	private String algorithm;
	static final Encoder MD5Encoder = new Encoder('MD5')
	/**
	 * @param algorithm
	 */
	public Encoder(String algorithm) {
		super();
		this.algorithm = algorithm;
	}
	
	/**
	 * @param inputString
	 * @return encoded string
	 */
	public String encode(String inputString) {
		MessageDigest digest = MessageDigest.getInstance(algorithm);
		digest.update(inputString.getBytes());
		return (new BASE64Encoder()).encode(digest.digest());
	}
}
